/*     */ package com.infoservice.schedule.queue;
/*     */ 
/*     */ import com.infoservice.schedule.Constant;
/*     */ import com.infoservice.schedule.ScheduleException;
/*     */ import com.infoservice.schedule.po.ScheduleDao;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.HashSet;
/*     */ import java.util.Iterator;
/*     */ import java.util.LinkedList;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class TaskQueue extends Thread
/*     */ {
/*     */   private static TaskQueue taskLoader;
/*  36 */   private Logger logger = Logger.getLogger(TaskQueue.class);
/*  37 */   private LinkedList<TaskBean> pendQueue = new LinkedList();
/*  38 */   private HashSet<TaskBean> taskQueue = new HashSet();
/*  39 */   private boolean isStop = false;
/*  40 */   private long previousLoadTime = 0L;
/*     */ 
/*  42 */   private TaskQueue(String name) { super(name); }
/*     */ 
/*     */   public void run() {
/*  45 */     while (!this.isStop)
/*  46 */       synchronized (this) {
/*  47 */         this.previousLoadTime = System.currentTimeMillis();
/*  48 */         this.logger.debug("Constant.TASK_LOAD_INTERVAL is " + Constant.TASK_LOAD_INTERVAL + " 分钟");
/*     */         try {
/*  50 */           if ((this.pendQueue.size() == 0) || (System.currentTimeMillis() - this.previousLoadTime >= Constant.TASK_LOAD_INTERVAL * 60L * 1000L))
/*  51 */             loadTaskBean();
/*  52 */           int size = this.pendQueue.size() - 1;
/*  53 */           for (int i = size; i >= 0; i--) {
/*  54 */             if ((dateEquals(((TaskBean)this.pendQueue.get(i)).getPlanStartDate())) || (((TaskBean)this.pendQueue.get(i)).getPlanRunType().intValue() == 0)) {
/*  55 */               synchronized (this.taskQueue) {
/*  56 */                 this.taskQueue.add((TaskBean)this.pendQueue.get(i));
/*  57 */                 this.taskQueue.notifyAll();
/*     */               }
/*  59 */               this.pendQueue.remove(i);
/*     */             }
/*     */           }
/*     */ 
/*  63 */           wait(Constant.TASK_LOAD_INTERVAL * 60L * 1000L);
/*     */         } catch (ScheduleException e) {
/*  65 */           this.logger.error(e.getMessage(), e);
/*     */           try {
/*  67 */             wait(300000L);
/*     */           } catch (InterruptedException e1) {
/*  69 */             this.logger.error(e1.getMessage(), e1);
/*     */           }
/*     */         } catch (InterruptedException e) {
/*  72 */           this.logger.error(e.getMessage(), e);
/*     */         }
/*     */       }
/*     */   }
/*     */ 
/*     */   public LinkedList<TaskBean> getPendQueue()
/*     */   {
/*  80 */     return this.pendQueue;
/*     */   }
/*     */ 
/*     */   private void loadTaskBean() {
/*  84 */     LinkedList list = ScheduleDao.loadPendQueue();
/*  85 */     this.previousLoadTime = System.currentTimeMillis();
/*  86 */     if ((list != null) && (list.size() > 0))
/*  87 */       this.pendQueue = list;
/*     */   }
/*     */ 
/*     */   public static synchronized TaskQueue getInstance()
/*     */   {
/*  92 */     if (taskLoader == null)
/*  93 */       taskLoader = new TaskQueue(TaskQueue.class.getSimpleName());
/*  94 */     return taskLoader;
/*     */   }
/*     */ 
/*     */   public boolean dateEquals(Date date) {
/*  98 */     Calendar cur = Calendar.getInstance();
/*  99 */     cur.set(14, 0);
/* 100 */     cur.set(13, 0);
/* 101 */     return date.getTime() <= cur.getTimeInMillis();
/*     */   }
/*     */ 
/*     */   public TaskBean getTaskBean() throws InterruptedException
/*     */   {
/* 106 */     synchronized (this.taskQueue) {
/* 107 */       if (this.taskQueue.size() > 0) {
/* 108 */         Iterator ie = this.taskQueue.iterator();
/* 109 */         TaskBean taskBean = (TaskBean)ie.next();
/* 110 */         ie.remove();
/* 111 */         return taskBean;
/*     */       }
/* 113 */       this.taskQueue.wait(1000L);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void stopThread()
/*     */   {
/* 119 */     this.isStop = true;
/* 120 */     interrupt();
/*     */   }
/*     */ }

/* Location:           D:\Workspace\Work\ASMP_DE\lib\frame3\InfoSchedule_1.0.03.jar
 * Qualified Name:     com.infoservice.schedule.queue.TaskQueue
 * JD-Core Version:    0.6.0
 */